package com.dongdong.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdong.pojo.TbSeller;
import com.dongdong.service.SellerService;
import com.dongdongshop.configresult.Result;
import com.dongdongshop.em.ResultEnum;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("seller")
public class SellerController {

    @Reference
    private SellerService selectservice;


    @RequestMapping("select")
    @ResponseBody
    public Result select(String name ,String nickName,String stu){
        List<TbSeller> tbSellers = selectservice.select(name,nickName,stu);
        if(tbSellers == null || tbSellers.size() <= 0){
            return Result.builResult(ResultEnum.ERROR);
        }
        return Result.builResult(ResultEnum.SUCCESS).setResout(tbSellers);
    }

    @RequestMapping("toupdate")
    @ResponseBody
    public Result toupdate(String id){
        TbSeller tbSeller = selectservice.selectId(id);
        if(tbSeller != null){
            return Result.builResult(ResultEnum.SUCCESS).setResout(tbSeller);
        }
        return Result.builResult(ResultEnum.SUCCESS);
    }

    @RequestMapping("update")
    @ResponseBody
    public Result update(TbSeller tbSeller) {
        boolean b = selectservice.update(tbSeller);
        if(b){
            return Result.builResult(ResultEnum.SUCCESS);
        }
        return Result.builResult(ResultEnum.ERROR);
    }
}
